<template>
  <div>
    <!-- 卡片视图区域 -->
    <el-card class="box-card">
      <!-- 布局 -->
      <el-row :gutter="20">
        <el-col :span="8">
          <!-- 搜索框及添加区域 -->
          <el-input
            placeholder="请输入内容"
            v-model="queryInfo.query"
            clearable
            @clear="getDialRecordList"
          >
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="getDialRecordList"
            ></el-button> </el-input
        ></el-col>
        <el-col :span="4">
          <el-button type="primary" @click="addDialogVisible = true"
            >添加抄表记录</el-button
          >
        </el-col>
      </el-row>
      <!-- 抄表记录列表区域 -->
      <el-table :data="dialRecordList" style="width: 100%" border stripe>
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column prop="dialId" label="仪表id"></el-table-column>
        <el-table-column prop="type" label="仪表类型">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.type === 0" type="success"
              >私表</el-tag
            >
            <el-tag v-else-if="scope.row.type === 1" type="danger"
              >公表</el-tag
            >
            <el-tag v-else type="warning">总表</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="num" label="表盘读数"></el-table-column>
        <el-table-column prop="time" label="抄表时间"></el-table-column>
        <el-table-column prop="empolyeeId" label="抄表人员id"></el-table-column>
        <el-table-column prop="isRecord" label="是否已抄">
           <template slot-scope="scope">
            <el-tag v-if="scope.row.isRecord === 0" type="success"
              >待抄</el-tag
            >
            <el-tag v-else type="warning">已抄</el-tag>
          </template>
        </el-table-column>
        
        <el-table-column label="操作" width="120px">
          <!-- 作用域插槽 -->
          <template slot-scope="scope">
            <!-- 修改按钮 -->
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
              @click="showEditDialog(scope.row.id)"
            ></el-button>
            <!-- 删除按钮 -->
            <el-button
              type="danger"
              icon="el-icon-delete"
              size="mini"
              @click="removeUserById(scope.row.id)"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 添加抄表记录的对话框 -->
      <el-dialog
        title="添加抄表记录信息"
        :visible.sync="addDialogVisible"
        width="50%"
        @close="addDialogReset"
      >
        <!-- 内容主题区域 -->
        <el-form
          :model="addForm"
          :rules="addFormRules"
          ref="addFormRef"
          label-width="150px"
        >
          <el-form-item label="仪表id" prop="dialId"><el-input v-model="addForm.dialId"></el-input></el-form-item>
          <el-form-item label="仪表类型（0私表，1公表，2总表）" prop="roomId"><el-input v-model="addForm.type"></el-input></el-form-item>
          <el-form-item label="表盘读数" prop="initvalue"><el-input v-model="addForm.num"></el-input></el-form-item>
          <el-form-item label="抄表时间" prop="times"><el-input v-model="addForm.time"></el-input></el-form-item>
          <el-form-item label="抄表人员id" prop="startTime"><el-input v-model="addForm.empolyeeId"></el-input></el-form-item>
          <el-form-item label="是否已抄（0待抄，1已抄）" prop="limit"><el-input v-model="addForm.isRecord"></el-input></el-form-item>
          
        </el-form>
        <!-- 底部区域 -->
        <span slot="footer" class="dialog-footer">
          <el-button @click="addDialogVisible = false">取 消</el-button>
          <el-button type="primary">确 定</el-button>
        </span>
      </el-dialog>
      <!-- 修改抄表记录信息的对话框 -->
      <el-dialog
        title="修改抄表记录信息"
        :visible.sync="editDialogVisible"
        width="50%"
        @close="editDialogClosed"
      >
        <el-form
          ref="editFormRef"
          :model="editForm"
          label-width="100px"
          :rules="editFormules"
          label-position="top"
        >
          <el-form-item label="仪表id" prop="dialId"><el-input v-model="editForm.dialId" disabled></el-input></el-form-item>
          <el-form-item label="仪表类型（0私表，1公表，2总表）" prop="type"><el-input v-model="editForm.roomId" disabled></el-input></el-form-item>
          <el-form-item label="表盘读数" prop="num"><el-input v-model="editForm.initvalue"></el-input></el-form-item>
          <el-form-item label="抄表时间" prop="time"><el-input v-model="editForm.times"></el-input></el-form-item>
          <el-form-item label="抄表人员id" prop="empolyeeId"><el-input v-model="editForm.startTime"></el-input></el-form-item>
          <el-form-item label="是否已抄（0待抄，1已抄）" prop="isRecord"><el-input v-model="editForm.limit"></el-input></el-form-item>
         
        </el-form>
        <!-- 底部区域 -->
        <span slot="footer" class="dialog-footer">
          <el-button @click="editDialogVisible = false">取 消</el-button>
          <el-button type="primary">确 定</el-button>
        </span>
      </el-dialog>
      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="this.queryInfo.pagenum"
        :page-sizes="[1, 2, 5, 10]"
        :page-size="this.queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>
<script>
export default {
  data() {
    return {
      // 获取抄表记录列表的参数对象
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 2
      },
      dialRecordList: [
        {
          dialId:13,
          type:0,
          num:9999,
          time:'2021-08-14',
          empolyeeId:118,
          isRecord:0,
        },
        {
         dialId:13,
          type:1,
          num:9999,
          time:'2021-08-14',
          empolyeeId:118,
          isRecord:1,
        },
        {
           dialId:13,
          type:2,
          num:9999,
          time:'2021-08-14',
          empolyeeId:118,
          isRecord:0,
        },
        {
         dialId:13,
          type:0,
          num:9999,
          time:'2021-08-14',
          empolyeeId:118,
          isRecord:1,
        },
      ],
      total: 0,
      // 控制添加对话框的显示与隐藏
      addDialogVisible: false,
      // 控制修改对话框的显示与隐藏
      editDialogVisible: false,
      // 添加抄表记录的表单数据
      addForm: {
        dialId:'',
        roomId:'',
        initvalue:'',
        times:'',
        startTime:'',
        limit:'',
        state:''
      },
      // 查询到的编辑抄表记录信息
      editForm: {},
      // 添加表单的验证规则对象
      addFormRules: {

      },
      // 修改抄表记录信息表单的验证规则
      editFormules: {

      }

    }

  },
  created() {
    this.getDialRecordList()
  },
  methods: {
    // 获取抄表记录档案列表
    getDialRecordList() {

    },

    // 展示编辑抄表记录的对话框
    showEditDialog() {
      this.editDialogVisible = !this.editDialogVisible
    },
    // 根据id删除抄表记录
    async removeUserById() {
      // 先弹框询问用户是否确定要删除
      const confirmResult = await this.$confirm('此操作将永久删除该抄表记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).catch(err => {
        return err
      })
      // 如果点击取消返回的是字符串cancel
      // 如果点击确认返回的是字符串confirm
      if (confirmResult !== 'confirm') {
        return this.$message.info('取消了删除')
      }
      return this.$message.error('删除抄表记录失败')
      // 刷新列表
      this.getDialRecordList()
    },
    // 监听修改抄表记录对话框的关闭事件
    editDialogClosed() {
      this.$refs.editFormRef.resetFields()
    },
    // 监听pagesize改变的事件
    handleSizeChange(newPageSize) {
      // console.log(newPageSize)
      this.queryInfo.pagesize = newPageSize
      // PageSize改变重新拿到抄表记录列表
      this.getDialRecordList()
    },
    // 监听当前页码改变的事件
    handleCurrentChange(newPageNum) {
      // console.log(newPageNum)
      this.queryInfo.pagenum = newPageNum
      this.getDialRecordList()
    },
    addDialogReset() {
      // 拿到表单的引用进行重置
      this.$refs.addFormRef.resetFields()
    },
  }
}
</script>
<style lang="less" scoped>
</style>